home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / obj-form.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-17  |  28.1 KB  |  752 lines

  1. /* coff object file format
  2.    Copyright (C) 1989, 1990, 1991, 1992, 1994 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef OBJ_FORMAT_H
  21. #define OBJ_FORMAT_H
  22.  
  23. #define OBJ_COFF 1
  24.  
  25. #ifndef BFD_ASSEMBLER
  26.  
  27. #define WORKING_DOT_WORD
  28. #define WARN_SIGNED_OVERFLOW_WORD
  29. #define OBJ_COFF_OMIT_OPTIONAL_HEADER
  30. #define BFD_HEADERS
  31. #define BFD
  32.  
  33. #endif
  34.  
  35. #include "targ-cpu.h"
  36.  
  37. #include "bfd.h"
  38.  
  39. /* This internal_lineno crap is to stop namespace pollution from the
  40.    bfd internal coff headerfile. */
  41. #define internal_lineno bfd_internal_lineno
  42. #include "coff/internal.h"
  43. #undef internal_lineno
  44.  
  45. /* CPU-specific setup:  */
  46. #ifdef TC_PPC
  47. #include "coff/rs6000.h"
  48. #endif
  49.  
  50. #ifdef TC_SPARC
  51. #include "coff/sparc.h"
  52. #ifdef TE_LYNX
  53. #define TARGET_FORMAT "coff-sparc-lynx"
  54. #else
  55. #define TARGET_FORMAT "coff-sparc"
  56. #endif
  57. #endif
  58.  
  59. #ifdef TC_I386
  60. #include "coff/i386.h"
  61. #ifndef TARGET_FORMAT
  62. #define TARGET_FORMAT "coff-i386"
  63. #endif
  64. #endif
  65.  
  66. #ifdef TC_M68K
  67. #include "coff/m68k.h"
  68. #ifndef TARGET_FORMAT
  69. #define TARGET_FORMAT "coff-m68k"
  70. #endif
  71. #endif
  72.  
  73. #ifdef TC_A29K
  74. #include "coff/a29k.h"
  75. #define TARGET_FORMAT "coff-a29k-big"
  76. #endif
  77.  
  78. #ifdef TC_I960
  79. #include "coff/i960.h"
  80. #define TARGET_FORMAT "coff-Intel-little"
  81. #endif
  82.  
  83. #ifdef TC_Z8K
  84. #include "coff/z8k.h"
  85. #define TARGET_FORMAT "coff-z8k"
  86. #endif
  87.  
  88. #ifdef TC_H8300
  89. #include "coff/h8300.h"
  90. #define TARGET_FORMAT "coff-h8300"
  91. #endif
  92.  
  93. #ifdef TC_H8500
  94. #include "coff/h8500.h"
  95. #define TARGET_FORMAT "coff-h8500"
  96. #endif
  97.  
  98. #ifdef TC_SH
  99. #include "coff/sh.h"
  100. #define TARGET_FORMAT "coff-sh"
  101. #endif
  102.  
  103. #ifdef TC_M88K
  104. #include "coff/m88k.h"
  105. #define TARGET_FORMAT "coff-m88kbcs"
  106. #endif
  107.  
  108. /* Targets may also set this.  Also, if BFD_ASSEMBLER is defined, this
  109.    will already have been defined.  */
  110. #undef SYMBOLS_NEED_BACKPOINTERS
  111. #define SYMBOLS_NEED_BACKPOINTERS 1
  112.  
  113. #ifndef OBJ_COFF_MAX_AUXENTRIES
  114. #define OBJ_COFF_MAX_AUXENTRIES 1
  115. #endif /* OBJ_COFF_MAX_AUXENTRIES */
  116.  
  117. /* ***********************************************************************
  118.  
  119.    This file really contains two implementations of the COFF back end.
  120.    They are in the process of being merged, but this is only a
  121.    preliminary, mechanical merging.  Many definitions that are
  122.    identical between the two are still found in both versions.
  123.  
  124.    The first version, with BFD_ASSEMBLER defined, uses high-level BFD
  125.    interfaces and data structures.  The second version, with
  126.    BFD_ASSEMBLER not defined, also uses BFD, but mostly for swapping
  127.    data structures and for doing the actual I/O.  The latter defines
  128.    the preprocessor symbols BFD and BFD_HEADERS.  Try not to let this
  129.    confuse you.
  130.  
  131.    These two are in the process of being merged, and eventually the
  132.    BFD_ASSEMBLER version should take over completely.  Release timing
  133.    issues and namespace problems convinced me to merge the two
  134.    together in this fashion, a little sooner than I would have liked.
  135.    The real merge should be much better done by the time the next
  136.    release comes out.
  137.  
  138.    For now, the structure of this file is:
  139.     <common>
  140.     #ifdef BFD_ASSEMBLER
  141.     <one version>
  142.     #else
  143.     <other version>
  144.     #endif
  145.     <common>
  146.    Unfortunately, the common portions are very small at the moment,
  147.    and many declarations or definitions are duplicated.  The structure
  148.    of obj-coff.c is similar.
  149.  
  150.    See doc/internals.texi for a brief discussion of the history, if
  151.    you care.
  152.  
  153.    Ken Raeburn, 5 May 1994
  154.  
  155.    *********************************************************************** */
  156.  
  157. #ifdef BFD_ASSEMBLER
  158.  
  159. #include "../bfd/libcoff.h"
  160.  
  161. /* SYMBOL TABLE */
  162.  
  163. /* Alter the field names, for now, until we've fixed up the other
  164.    references to use the new name.  */
  165. #ifdef TC_I960
  166. #define TC_SYMFIELD_TYPE    struct symbol *
  167. #define sy_tc            bal
  168. #endif
  169.  
  170. #define OBJ_SYMFIELD_TYPE    unsigned long
  171. #define sy_obj            sy_flags
  172.  
  173. #define SYM_AUXENT(S)    (&coffsymbol ((S)->bsym)->native[1].u.auxent)
  174.  
  175. #define DO_NOT_STRIP    0
  176. #define DO_STRIP    1
  177.  
  178. extern void obj_coff_section PARAMS ((int));
  179.  
  180. /* The number of auxiliary entries */
  181. #define S_GET_NUMBER_AUXILIARY(s)    (coffsymbol((s)->bsym)->native->u.syment.n_numaux)
  182. /* The number of auxiliary entries */
  183. #define S_SET_NUMBER_AUXILIARY(s,v)    (S_GET_NUMBER_AUXILIARY (s) = (v))
  184.  
  185. /* True if a symbol name is in the string table, i.e. its length is > 8. */
  186. #define S_IS_STRING(s)        (strlen(S_GET_NAME(s)) > 8 ? 1 : 0)
  187.  
  188. extern int S_SET_DATA_TYPE PARAMS ((struct symbol *, int));
  189. extern int S_SET_STORAGE_CLASS PARAMS ((struct symbol *, int));
  190. extern int S_GET_STORAGE_CLASS PARAMS ((struct symbol *));
  191. extern void SA_SET_SYM_ENDNDX PARAMS ((struct symbol *, struct symbol *));
  192.  
  193. /* Auxiliary entry macros. SA_ stands for symbol auxiliary */
  194. /* Omit the tv related fields */
  195. /* Accessors */
  196.  
  197. #define SA_GET_SYM_TAGNDX(s)    (SYM_AUXENT (s)->x_sym.x_tagndx.l)
  198. #define SA_GET_SYM_LNNO(s)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
  199. #define SA_GET_SYM_SIZE(s)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
  200. #define SA_GET_SYM_FSIZE(s)    (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
  201. #define SA_GET_SYM_LNNOPTR(s)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
  202. #define SA_GET_SYM_ENDNDX(s)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx)
  203. #define SA_GET_SYM_DIMEN(s,i)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
  204. #define SA_GET_FILE_FNAME(s)    (SYM_AUXENT (s)->x_file.x_fname)
  205. #define SA_GET_SCN_SCNLEN(s)    (SYM_AUXENT (s)->x_scn.x_scnlen)
  206. #define SA_GET_SCN_NRELOC(s)    (SYM_AUXENT (s)->x_scn.x_nreloc)
  207. #define SA_GET_SCN_NLINNO(s)    (SYM_AUXENT (s)->x_scn.x_nlinno)
  208.  
  209. #define SA_SET_SYM_LNNO(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno=(v))
  210. #define SA_SET_SYM_SIZE(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size=(v))
  211. #define SA_SET_SYM_FSIZE(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_fsize=(v))
  212. #define SA_SET_SYM_LNNOPTR(s,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr=(v))
  213. #define SA_SET_SYM_DIMEN(s,i,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]=(v))
  214. #define SA_SET_FILE_FNAME(s,v)    strncpy(SYM_AUXENT (s)->x_file.x_fname,(v),FILNMLEN)
  215. #define SA_SET_SCN_SCNLEN(s,v)    (SYM_AUXENT (s)->x_scn.x_scnlen=(v))
  216. #define SA_SET_SCN_NRELOC(s,v)    (SYM_AUXENT (s)->x_scn.x_nreloc=(v))
  217. #define SA_SET_SCN_NLINNO(s,v)    (SYM_AUXENT (s)->x_scn.x_nlinno=(v))
  218.  
  219. /*
  220.  * Internal use only definitions. SF_ stands for symbol flags.
  221.  *
  222.  * These values can be assigned to sy_symbol.ost_flags field of a symbolS.
  223.  *
  224.  * You'll break i960 if you shift the SYSPROC bits anywhere else.  for
  225.  * more on the balname/callname hack, see tc-i960.h.  b.out is done
  226.  * differently.
  227.  */
  228.  
  229. #define SF_I960_MASK    (0x000001ff)    /* Bits 0-8 are used by the i960 port. */
  230. #define SF_SYSPROC    (0x0000003f)    /* bits 0-5 are used to store the sysproc number */
  231. #define SF_IS_SYSPROC    (0x00000040)    /* bit 6 marks symbols that are sysprocs */
  232. #define SF_BALNAME    (0x00000080)    /* bit 7 marks BALNAME symbols */
  233. #define SF_CALLNAME    (0x00000100)    /* bit 8 marks CALLNAME symbols */
  234.  
  235. #define SF_NORMAL_MASK    (0x0000ffff)    /* bits 12-15 are general purpose. */
  236.  
  237. #define SF_STATICS    (0x00001000)    /* Mark the .text & all symbols */
  238. #define SF_DEFINED    (0x00002000)    /* Symbol is defined in this file */
  239. #define SF_STRING    (0x00004000)    /* Symbol name length > 8 */
  240. #define SF_LOCAL    (0x00008000)    /* Symbol must not be emitted */
  241.  
  242. #define SF_DEBUG_MASK    (0xffff0000)    /* bits 16-31 are debug info */
  243.  
  244. #define SF_FUNCTION    (0x00010000)    /* The symbol is a function */
  245. #define SF_PROCESS    (0x00020000)    /* Process symbol before write */
  246. #define SF_TAGGED    (0x00040000)    /* Is associated with a tag */
  247. #define SF_TAG        (0x00080000)    /* Is a tag */
  248. #define SF_DEBUG    (0x00100000)    /* Is in debug or abs section */
  249. #define SF_GET_SEGMENT    (0x00200000)    /* Get the section of the forward symbol. */
  250. /* All other bits are unused. */
  251.  
  252. /* Accessors */
  253. #define SF_GET(s)        ((s)->sy_flags)
  254. #define SF_GET_DEBUG(s)        ((s)->bsym->flags & BSF_DEBUGGING)
  255. #define SF_SET_DEBUG(s)        ((s)->bsym->flags |= BSF_DEBUGGING)
  256. #define SF_GET_NORMAL_FIELD(s)    (SF_GET (s) & SF_NORMAL_MASK)
  257. #define SF_GET_DEBUG_FIELD(s)    (SF_GET (s) & SF_DEBUG_MASK)
  258. #define SF_GET_FILE(s)        (SF_GET (s) & SF_FILE)
  259. #define SF_GET_STATICS(s)    (SF_GET (s) & SF_STATICS)
  260. #define SF_GET_DEFINED(s)    (SF_GET (s) & SF_DEFINED)
  261. #define SF_GET_STRING(s)    (SF_GET (s) & SF_STRING)
  262. #define SF_GET_LOCAL(s)        (SF_GET (s) & SF_LOCAL)
  263. #define SF_GET_FUNCTION(s)      (SF_GET (s) & SF_FUNCTION)
  264. #define SF_GET_PROCESS(s)    (SF_GET (s) & SF_PROCESS)
  265. #define SF_GET_TAGGED(s)    (SF_GET (s) & SF_TAGGED)
  266. #define SF_GET_TAG(s)        (SF_GET (s) & SF_TAG)
  267. #define SF_GET_GET_SEGMENT(s)    (SF_GET (s) & SF_GET_SEGMENT)
  268. #define SF_GET_I960(s)        (SF_GET (s) & SF_I960_MASK)    /* used by i960 */
  269. #define SF_GET_BALNAME(s)    (SF_GET (s) & SF_BALNAME)    /* used by i960 */
  270. #define SF_GET_CALLNAME(s)    (SF_GET (s) & SF_CALLNAME)    /* used by i960 */
  271. #define SF_GET_IS_SYSPROC(s)    (SF_GET (s) & SF_IS_SYSPROC)    /* used by i960 */
  272. #define SF_GET_SYSPROC(s)    (SF_GET (s) & SF_SYSPROC)    /* used by i960 */
  273.  
  274. /* Modifiers */
  275. #define SF_SET(s,v)        (SF_GET (s) = (v))
  276. #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
  277. #define SF_SET_DEBUG_FIELD(s,v)    (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
  278. #define SF_SET_FILE(s)        (SF_GET (s) |= SF_FILE)
  279. #define SF_SET_STATICS(s)    (SF_GET (s) |= SF_STATICS)
  280. #define SF_SET_DEFINED(s)    (SF_GET (s) |= SF_DEFINED)
  281. #define SF_SET_STRING(s)    (SF_GET (s) |= SF_STRING)
  282. #define SF_SET_LOCAL(s)        (SF_GET (s) |= SF_LOCAL)
  283. #define SF_CLEAR_LOCAL(s)    (SF_GET (s) &= ~SF_LOCAL)
  284. #define SF_SET_FUNCTION(s)      (SF_GET (s) |= SF_FUNCTION)
  285. #define SF_SET_PROCESS(s)    (SF_GET (s) |= SF_PROCESS)
  286. #define SF_SET_TAGGED(s)    (SF_GET (s) |= SF_TAGGED)
  287. #define SF_SET_TAG(s)        (SF_GET (s) |= SF_TAG)
  288. #define SF_SET_GET_SEGMENT(s)    (SF_GET (s) |= SF_GET_SEGMENT)
  289. #define SF_SET_I960(s,v)    (SF_GET (s) |= ((v) & SF_I960_MASK))    /* used by i960 */
  290. #define SF_SET_BALNAME(s)    (SF_GET (s) |= SF_BALNAME)    /* used by i960 */
  291. #define SF_SET_CALLNAME(s)    (SF_GET (s) |= SF_CALLNAME)    /* used by i960 */
  292. #define SF_SET_IS_SYSPROC(s)    (SF_GET (s) |= SF_IS_SYSPROC)    /* used by i960 */
  293. #define SF_SET_SYSPROC(s,v)    (SF_GET (s) |= ((v) & SF_SYSPROC))    /* used by i960 */
  294.  
  295. /* --------------  Line number handling ------- */
  296. extern int text_lineno_number;
  297. extern int coff_line_base;
  298.  
  299. #define obj_emit_lineno(WHERE,LINE,FILE_START)    abort ()
  300. extern void coff_add_linesym PARAMS ((struct symbol *));
  301.  
  302.  
  303. void c_dot_file_symbol PARAMS ((char *filename));
  304.  
  305. extern void coff_frob_symbol PARAMS ((struct symbol *, int *));
  306. extern void coff_adjust_symtab PARAMS ((void));
  307. extern void coff_frob_section PARAMS ((segT));
  308. extern void coff_adjust_section_syms PARAMS ((bfd *, asection *, PTR));
  309. extern void coff_frob_file PARAMS ((void));
  310. #define obj_frob_symbol(S,P)     coff_frob_symbol(S,&P)
  311. #define obj_adjust_symtab()    coff_adjust_symtab()
  312. #define obj_frob_section(S)    coff_frob_section (S)
  313. #define obj_frob_file()        coff_frob_file ()
  314.  
  315. extern struct symbol *coff_last_function;
  316.  
  317. /* Forward the segment of a forwarded symbol, handle assignments that
  318.    just copy symbol values, etc.  */
  319. #ifndef TE_I386AIX
  320. #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src) \
  321.   (SF_GET_GET_SEGMENT (dest) \
  322.    ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
  323.    : 0)
  324. #else
  325. #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src) \
  326.   (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \
  327.    ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
  328.    : 0)
  329. #endif
  330.  
  331. /* sanity check */
  332.  
  333. #ifdef TC_I960
  334. #ifndef C_LEAFSTAT
  335. hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it.
  336. #endif /* no C_LEAFSTAT */
  337. #endif /* TC_I960 */
  338.  
  339. #else /* not BFD_ASSEMBLER */
  340.  
  341. #ifdef TC_A29K
  342. /* Allow translate from aout relocs to coff relocs */
  343. #define NO_RELOC 20
  344. #define RELOC_32 1
  345. #define RELOC_8 2
  346. #define RELOC_CONST 3
  347. #define RELOC_CONSTH 4
  348. #define RELOC_JUMPTARG 5
  349. #define RELOC_BASE22 6
  350. #define RELOC_HI22 7
  351. #define RELOC_LO10 8
  352. #define RELOC_BASE13 9
  353. #define RELOC_WDISP22 10
  354. #define RELOC_WDISP30 11
  355. #endif
  356.  
  357. extern const segT N_TYPE_seg[];
  358.  
  359. /* Magic number of paged executable. */
  360. #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE    0x8300
  361.  
  362.  
  363. /* SYMBOL TABLE */
  364.  
  365. /* Symbol table entry data type */
  366.  
  367. typedef struct
  368. {
  369.   /* Basic symbol */
  370.   struct internal_syment ost_entry;
  371.   /* Auxiliary entry. */
  372.   union internal_auxent ost_auxent[OBJ_COFF_MAX_AUXENTRIES];
  373.   /* obj_coff internal use only flags */
  374.   unsigned int ost_flags;
  375. } obj_symbol_type;
  376.  
  377. #ifndef DO_NOT_STRIP
  378. #define DO_NOT_STRIP    0
  379. #define DO_STRIP    1
  380. #endif
  381. /* Symbol table macros and constants */
  382.  
  383. /* Possible and usefull section number in symbol table
  384.  * The values of TEXT, DATA and BSS may not be portable.
  385.  */
  386.  
  387. #define C_ABS_SECTION        N_ABS
  388. #define C_UNDEF_SECTION        N_UNDEF
  389. #define C_DEBUG_SECTION        N_DEBUG
  390. #define C_NTV_SECTION        N_TV
  391. #define C_PTV_SECTION        P_TV
  392. #define C_REGISTER_SECTION    20
  393.  
  394. /*
  395.  *  Macros to extract information from a symbol table entry.
  396.  *  This syntaxic indirection allows independence regarding a.out or coff.
  397.  *  The argument (s) of all these macros is a pointer to a symbol table entry.
  398.  */
  399.  
  400. /* Predicates */
  401. /* True if the symbol is external */
  402. #define S_IS_EXTERNAL(s)        ((s)->sy_symbol.ost_entry.n_scnum == C_UNDEF_SECTION)
  403. /* True if symbol has been defined, ie :
  404.    section > 0 (DATA, TEXT or BSS)
  405.    section == 0 and value > 0 (external bss symbol) */
  406. #define S_IS_DEFINED(s) \
  407.   ((s)->sy_symbol.ost_entry.n_scnum > C_UNDEF_SECTION \
  408.    || ((s)->sy_symbol.ost_entry.n_scnum == C_UNDEF_SECTION \
  409.        && S_GET_VALUE (s) > 0) \
  410.    || ((s)->sy_symbol.ost_entry.n_scnum == C_ABS_SECTION))
  411. /* True if a debug special symbol entry */
  412. #define S_IS_DEBUG(s)        ((s)->sy_symbol.ost_entry.n_scnum == C_DEBUG_SECTION)
  413. /* True if a symbol is local symbol name */
  414. /* A symbol name whose name includes ^A is a gas internal pseudo symbol */
  415. #define S_IS_LOCAL(s) \
  416.   ((s)->sy_symbol.ost_entry.n_scnum == C_REGISTER_SECTION \
  417.    || (S_LOCAL_NAME(s) && !flag_keep_locals) \
  418.    || (strchr (S_GET_NAME (s), '\001') != NULL))
  419. /* True if a symbol is not defined in this file */
  420. #define S_IS_EXTERN(s)        ((s)->sy_symbol.ost_entry.n_scnum == 0 \
  421.                  && S_GET_VALUE (s) == 0)
  422. /*
  423.  * True if a symbol can be multiply defined (bss symbols have this def
  424.  * though it is bad practice)
  425.  */
  426. #define S_IS_COMMON(s)        ((s)->sy_symbol.ost_entry.n_scnum == 0 \
  427.                  && S_GET_VALUE (s) != 0)
  428. /* True if a symbol name is in the string table, i.e. its length is > 8. */
  429. #define S_IS_STRING(s)        (strlen(S_GET_NAME(s)) > 8 ? 1 : 0)
  430.  
  431. /* Accessors */
  432. /* The name of the symbol */
  433. #define S_GET_NAME(s)        ((char*)(s)->sy_symbol.ost_entry.n_offset)
  434. /* The pointer to the string table */
  435. #define S_GET_OFFSET(s)         ((s)->sy_symbol.ost_entry.n_offset)
  436. /* The numeric value of the segment */
  437. #define S_GET_SEGMENT(s)   s_get_segment(s)
  438. /* The data type */
  439. #define S_GET_DATA_TYPE(s)    ((s)->sy_symbol.ost_entry.n_type)
  440. /* The storage class */
  441. #define S_GET_STORAGE_CLASS(s)    ((s)->sy_symbol.ost_entry.n_sclass)
  442. /* The number of auxiliary entries */
  443. #define S_GET_NUMBER_AUXILIARY(s)    ((s)->sy_symbol.ost_entry.n_numaux)
  444.  
  445. /* Modifiers */
  446. /* Set the name of the symbol */
  447. #define S_SET_NAME(s,v)        ((s)->sy_symbol.ost_entry.n_offset = (unsigned long)(v))
  448. /* Set the offset of the symbol */
  449. #define S_SET_OFFSET(s,v)    ((s)->sy_symbol.ost_entry.n_offset = (v))
  450. /* The numeric value of the segment */
  451. #define S_SET_SEGMENT(s,v)    ((s)->sy_symbol.ost_entry.n_scnum = SEGMENT_TO_SYMBOL_TYPE(v))
  452. /* The data type */
  453. #define S_SET_DATA_TYPE(s,v)    ((s)->sy_symbol.ost_entry.n_type = (v))
  454. /* The storage class */
  455. #define S_SET_STORAGE_CLASS(s,v)    ((s)->sy_symbol.ost_entry.n_sclass = (v))
  456. /* The number of auxiliary entries */
  457. #define S_SET_NUMBER_AUXILIARY(s,v)    ((s)->sy_symbol.ost_entry.n_numaux = (v))
  458.  
  459. /* Additional modifiers */
  460. /* The symbol is external (does not mean undefined) */
  461. #define S_SET_EXTERNAL(s)       { S_SET_STORAGE_CLASS(s, C_EXT) ; SF_CLEAR_LOCAL(s); }
  462.  
  463. /* Auxiliary entry macros. SA_ stands for symbol auxiliary */
  464. /* Omit the tv related fields */
  465. /* Accessors */
  466. #define SYM_AUXENT(S)    (&(S)->sy_symbol.ost_auxent[0])
  467.  
  468. #define SA_GET_SYM_TAGNDX(s)    (SYM_AUXENT (s)->x_sym.x_tagndx.l)
  469. #define SA_GET_SYM_LNNO(s)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
  470. #define SA_GET_SYM_SIZE(s)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
  471. #define SA_GET_SYM_FSIZE(s)    (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
  472. #define SA_GET_SYM_LNNOPTR(s)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
  473. #define SA_GET_SYM_ENDNDX(s)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx.l)
  474. #define SA_GET_SYM_DIMEN(s,i)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
  475. #define SA_GET_FILE_FNAME(s)    (SYM_AUXENT (s)->x_file.x_fname)
  476. #define SA_GET_SCN_SCNLEN(s)    (SYM_AUXENT (s)->x_scn.x_scnlen)
  477. #define SA_GET_SCN_NRELOC(s)    (SYM_AUXENT (s)->x_scn.x_nreloc)
  478. #define SA_GET_SCN_NLINNO(s)    (SYM_AUXENT (s)->x_scn.x_nlinno)
  479.  
  480. /* Modifiers */
  481. #define SA_SET_SYM_TAGNDX(s,v)    (SYM_AUXENT (s)->x_sym.x_tagndx.l=(v))
  482. #define SA_SET_SYM_LNNO(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno=(v))
  483. #define SA_SET_SYM_SIZE(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size=(v))
  484. #define SA_SET_SYM_FSIZE(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_fsize=(v))
  485. #define SA_SET_SYM_LNNOPTR(s,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr=(v))
  486. #define SA_SET_SYM_ENDNDX(s,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx.l=(v))
  487. #define SA_SET_SYM_DIMEN(s,i,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]=(v))
  488. #define SA_SET_FILE_FNAME(s,v)    strncpy(SYM_AUXENT (s)->x_file.x_fname,(v),FILNMLEN)
  489. #define SA_SET_SCN_SCNLEN(s,v)    (SYM_AUXENT (s)->x_scn.x_scnlen=(v))
  490. #define SA_SET_SCN_NRELOC(s,v)    (SYM_AUXENT (s)->x_scn.x_nreloc=(v))
  491. #define SA_SET_SCN_NLINNO(s,v)    (SYM_AUXENT (s)->x_scn.x_nlinno=(v))
  492.  
  493. /*
  494.  * Internal use only definitions. SF_ stands for symbol flags.
  495.  *
  496.  * These values can be assigned to sy_symbol.ost_flags field of a symbolS.
  497.  *
  498.  * You'll break i960 if you shift the SYSPROC bits anywhere else.  for
  499.  * more on the balname/callname hack, see tc-i960.h.  b.out is done
  500.  * differently.
  501.  */
  502.  
  503. #define SF_I960_MASK    (0x000001ff)    /* Bits 0-8 are used by the i960 port. */
  504. #define SF_SYSPROC    (0x0000003f)    /* bits 0-5 are used to store the sysproc number */
  505. #define SF_IS_SYSPROC    (0x00000040)    /* bit 6 marks symbols that are sysprocs */
  506. #define SF_BALNAME    (0x00000080)    /* bit 7 marks BALNAME symbols */
  507. #define SF_CALLNAME    (0x00000100)    /* bit 8 marks CALLNAME symbols */
  508.  
  509. #define SF_NORMAL_MASK    (0x0000ffff)    /* bits 12-15 are general purpose. */
  510.  
  511. #define SF_STATICS    (0x00001000)    /* Mark the .text & all symbols */
  512. #define SF_DEFINED    (0x00002000)    /* Symbol is defined in this file */
  513. #define SF_STRING    (0x00004000)    /* Symbol name length > 8 */
  514. #define SF_LOCAL    (0x00008000)    /* Symbol must not be emitted */
  515.  
  516. #define SF_DEBUG_MASK    (0xffff0000)    /* bits 16-31 are debug info */
  517.  
  518. #define SF_FUNCTION    (0x00010000)    /* The symbol is a function */
  519. #define SF_PROCESS    (0x00020000)    /* Process symbol before write */
  520. #define SF_TAGGED    (0x00040000)    /* Is associated with a tag */
  521. #define SF_TAG        (0x00080000)    /* Is a tag */
  522. #define SF_DEBUG    (0x00100000)    /* Is in debug or abs section */
  523. #define SF_GET_SEGMENT    (0x00200000)    /* Get the section of the forward symbol. */
  524. /* All other bits are unused. */
  525.  
  526. /* Accessors */
  527. #define SF_GET(s)        ((s)->sy_symbol.ost_flags)
  528. #define SF_GET_NORMAL_FIELD(s)    (SF_GET (s) & SF_NORMAL_MASK)
  529. #define SF_GET_DEBUG_FIELD(s)    (SF_GET (s) & SF_DEBUG_MASK)
  530. #define SF_GET_FILE(s)        (SF_GET (s) & SF_FILE)
  531. #define SF_GET_STATICS(s)    (SF_GET (s) & SF_STATICS)
  532. #define SF_GET_DEFINED(s)    (SF_GET (s) & SF_DEFINED)
  533. #define SF_GET_STRING(s)    (SF_GET (s) & SF_STRING)
  534. #define SF_GET_LOCAL(s)        (SF_GET (s) & SF_LOCAL)
  535. #define SF_GET_FUNCTION(s)      (SF_GET (s) & SF_FUNCTION)
  536. #define SF_GET_PROCESS(s)    (SF_GET (s) & SF_PROCESS)
  537. #define SF_GET_DEBUG(s)        (SF_GET (s) & SF_DEBUG)
  538. #define SF_GET_TAGGED(s)    (SF_GET (s) & SF_TAGGED)
  539. #define SF_GET_TAG(s)        (SF_GET (s) & SF_TAG)
  540. #define SF_GET_GET_SEGMENT(s)    (SF_GET (s) & SF_GET_SEGMENT)
  541. #define SF_GET_I960(s)        (SF_GET (s) & SF_I960_MASK)    /* used by i960 */
  542. #define SF_GET_BALNAME(s)    (SF_GET (s) & SF_BALNAME)    /* used by i960 */
  543. #define SF_GET_CALLNAME(s)    (SF_GET (s) & SF_CALLNAME)    /* used by i960 */
  544. #define SF_GET_IS_SYSPROC(s)    (SF_GET (s) & SF_IS_SYSPROC)    /* used by i960 */
  545. #define SF_GET_SYSPROC(s)    (SF_GET (s) & SF_SYSPROC)    /* used by i960 */
  546.  
  547. /* Modifiers */
  548. #define SF_SET(s,v)        (SF_GET (s) = (v))
  549. #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
  550. #define SF_SET_DEBUG_FIELD(s,v)    (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
  551. #define SF_SET_FILE(s)        (SF_GET (s) |= SF_FILE)
  552. #define SF_SET_STATICS(s)    (SF_GET (s) |= SF_STATICS)
  553. #define SF_SET_DEFINED(s)    (SF_GET (s) |= SF_DEFINED)
  554. #define SF_SET_STRING(s)    (SF_GET (s) |= SF_STRING)
  555. #define SF_SET_LOCAL(s)        (SF_GET (s) |= SF_LOCAL)
  556. #define SF_CLEAR_LOCAL(s)    (SF_GET (s) &= ~SF_LOCAL)
  557. #define SF_SET_FUNCTION(s)      (SF_GET (s) |= SF_FUNCTION)
  558. #define SF_SET_PROCESS(s)    (SF_GET (s) |= SF_PROCESS)
  559. #define SF_SET_DEBUG(s)        (SF_GET (s) |= SF_DEBUG)
  560. #define SF_SET_TAGGED(s)    (SF_GET (s) |= SF_TAGGED)
  561. #define SF_SET_TAG(s)        (SF_GET (s) |= SF_TAG)
  562. #define SF_SET_GET_SEGMENT(s)    (SF_GET (s) |= SF_GET_SEGMENT)
  563. #define SF_SET_I960(s,v)    (SF_GET (s) |= ((v) & SF_I960_MASK))    /* used by i960 */
  564. #define SF_SET_BALNAME(s)    (SF_GET (s) |= SF_BALNAME)    /* used by i960 */
  565. #define SF_SET_CALLNAME(s)    (SF_GET (s) |= SF_CALLNAME)    /* used by i960 */
  566. #define SF_SET_IS_SYSPROC(s)    (SF_GET (s) |= SF_IS_SYSPROC)    /* used by i960 */
  567. #define SF_SET_SYSPROC(s,v)    (SF_GET (s) |= ((v) & SF_SYSPROC))    /* used by i960 */
  568.  
  569. /* File header macro and type definition */
  570.  
  571. /*
  572.  * File position calculators. Beware to use them when all the
  573.  * appropriate fields are set in the header.
  574.  */
  575.  
  576. #ifdef OBJ_COFF_OMIT_OPTIONAL_HEADER
  577. #define OBJ_COFF_AOUTHDRSZ (0)
  578. #else
  579. #define OBJ_COFF_AOUTHDRSZ (AOUTHDRSZ)
  580. #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
  581.  
  582. #define H_GET_FILE_SIZE(h) \
  583.     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
  584.        H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
  585.        H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
  586.        H_GET_RELOCATION_SIZE(h) + H_GET_LINENO_SIZE(h) + \
  587.        H_GET_SYMBOL_TABLE_SIZE(h) + \
  588.        (h)->string_table_size)
  589. #define H_GET_TEXT_FILE_OFFSET(h) \
  590.     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
  591.        H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ)
  592. #define H_GET_DATA_FILE_OFFSET(h) \
  593.     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
  594.        H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
  595.        H_GET_TEXT_SIZE(h))
  596. #define H_GET_BSS_FILE_OFFSET(h) 0
  597. #define H_GET_RELOCATION_FILE_OFFSET(h) \
  598.     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
  599.        H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
  600.        H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h))
  601. #define H_GET_LINENO_FILE_OFFSET(h) \
  602.     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
  603.        H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
  604.        H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
  605.        H_GET_RELOCATION_SIZE(h))
  606. #define H_GET_SYMBOL_TABLE_FILE_OFFSET(h) \
  607.     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
  608.        H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
  609.        H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
  610.        H_GET_RELOCATION_SIZE(h) + H_GET_LINENO_SIZE(h))
  611.  
  612. /* Accessors */
  613. /* aouthdr */
  614. #define H_GET_MAGIC_NUMBER(h)           ((h)->aouthdr.magic)
  615. #define H_GET_VERSION_STAMP(h)        ((h)->aouthdr.vstamp)
  616. #define H_GET_TEXT_SIZE(h)              ((h)->aouthdr.tsize)
  617. #define H_GET_DATA_SIZE(h)              ((h)->aouthdr.dsize)
  618. #define H_GET_BSS_SIZE(h)               ((h)->aouthdr.bsize)
  619. #define H_GET_ENTRY_POINT(h)            ((h)->aouthdr.entry)
  620. #define H_GET_TEXT_START(h)        ((h)->aouthdr.text_start)
  621. #define H_GET_DATA_START(h)        ((h)->aouthdr.data_start)
  622. /* filehdr */
  623. #define H_GET_FILE_MAGIC_NUMBER(h)    ((h)->filehdr.f_magic)
  624. #define H_GET_NUMBER_OF_SECTIONS(h)    ((h)->filehdr.f_nscns)
  625. #define H_GET_TIME_STAMP(h)        ((h)->filehdr.f_timdat)
  626. #define H_GET_SYMBOL_TABLE_POINTER(h)    ((h)->filehdr.f_symptr)
  627. #define H_GET_SYMBOL_COUNT(h)        ((h)->filehdr.f_nsyms)
  628. #define H_GET_SYMBOL_TABLE_SIZE(h)    (H_GET_SYMBOL_COUNT(h) * SYMESZ)
  629. #define H_GET_SIZEOF_OPTIONAL_HEADER(h)    ((h)->filehdr.f_opthdr)
  630. #define H_GET_FLAGS(h)            ((h)->filehdr.f_flags)
  631. /* Extra fields to achieve bsd a.out compatibility and for convenience */
  632. #define H_GET_RELOCATION_SIZE(h)       ((h)->relocation_size)
  633. #define H_GET_STRING_SIZE(h)            ((h)->string_table_size)
  634. #define H_GET_LINENO_SIZE(h)            ((h)->lineno_size)
  635.  
  636. #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
  637. #define H_GET_HEADER_SIZE(h)        (sizeof(FILHDR) \
  638.                      + sizeof(AOUTHDR)\
  639.                      + (H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ))
  640. #else /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
  641. #define H_GET_HEADER_SIZE(h)        (sizeof(FILHDR) \
  642.                      + (H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ))
  643. #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
  644.  
  645. #define H_GET_TEXT_RELOCATION_SIZE(h)    (text_section_header.s_nreloc * RELSZ)
  646. #define H_GET_DATA_RELOCATION_SIZE(h)    (data_section_header.s_nreloc * RELSZ)
  647.  
  648. /* Modifiers */
  649. /* aouthdr */
  650. #define H_SET_MAGIC_NUMBER(h,v)         ((h)->aouthdr.magic = (v))
  651. #define H_SET_VERSION_STAMP(h,v)    ((h)->aouthdr.vstamp = (v))
  652. #define H_SET_TEXT_SIZE(h,v)            ((h)->aouthdr.tsize = (v))
  653. #define H_SET_DATA_SIZE(h,v)            ((h)->aouthdr.dsize = (v))
  654. #define H_SET_BSS_SIZE(h,v)             ((h)->aouthdr.bsize = (v))
  655. #define H_SET_ENTRY_POINT(h,v)          ((h)->aouthdr.entry = (v))
  656. #define H_SET_TEXT_START(h,v)        ((h)->aouthdr.text_start = (v))
  657. #define H_SET_DATA_START(h,v)        ((h)->aouthdr.data_start = (v))
  658. /* filehdr */
  659. #define H_SET_FILE_MAGIC_NUMBER(h,v)    ((h)->filehdr.f_magic = (v))
  660. #define H_SET_NUMBER_OF_SECTIONS(h,v)    ((h)->filehdr.f_nscns = (v))
  661. #define H_SET_TIME_STAMP(h,v)        ((h)->filehdr.f_timdat = (v))
  662. #define H_SET_SYMBOL_TABLE_POINTER(h,v)    ((h)->filehdr.f_symptr = (v))
  663. #define H_SET_SYMBOL_TABLE_SIZE(h,v)    ((h)->filehdr.f_nsyms = (v))
  664. #define H_SET_SIZEOF_OPTIONAL_HEADER(h,v) ((h)->filehdr.f_opthdr = (v))
  665. #define H_SET_FLAGS(h,v)        ((h)->filehdr.f_flags = (v))
  666. /* Extra fields to achieve bsd a.out compatibility and for convinience */
  667. #define H_SET_RELOCATION_SIZE(h,t,d)     ((h)->relocation_size = (t)+(d))
  668. #define H_SET_STRING_SIZE(h,v)          ((h)->string_table_size = (v))
  669. #define H_SET_LINENO_SIZE(h,v)          ((h)->lineno_size = (v))
  670.  
  671. /* Segment flipping */
  672.  
  673. typedef struct
  674. {
  675.   struct internal_aouthdr aouthdr;    /* a.out header */
  676.   struct internal_filehdr filehdr;    /* File header, not machine dep. */
  677.   long string_table_size;    /* names + '\0' + sizeof(int) */
  678.   long relocation_size;    /* Cumulated size of relocation
  679.                information for all sections in
  680.                bytes. */
  681.   long lineno_size;        /* Size of the line number information
  682.                    table in bytes */
  683. } object_headers;
  684.  
  685.  
  686.  
  687. struct lineno_list
  688. {
  689.   struct bfd_internal_lineno line;
  690.   char *frag;            /* Frag to which the line number is related */
  691.   struct lineno_list *next;    /* Forward chain pointer */
  692. };
  693.  
  694.  
  695.  
  696.  
  697. #define obj_segment_name(i) (segment_info[(int) (i)].scnhdr.s_name)
  698.  
  699. #define obj_add_segment(s) obj_coff_add_segment (s)
  700.  
  701. extern segT obj_coff_add_segment PARAMS ((const char *));
  702.  
  703. extern void obj_coff_section PARAMS ((int));
  704.  
  705. extern void c_dot_file_symbol PARAMS ((char *filename));
  706. extern void obj_extra_stuff PARAMS ((object_headers * headers));
  707.  
  708. extern segT s_get_segment PARAMS ((struct symbol * ptr));
  709.  
  710. extern void c_section_header PARAMS ((struct internal_scnhdr * header,
  711.                       char *name,
  712.                       long core_address,
  713.                       long size,
  714.                       long data_ptr,
  715.                       long reloc_ptr,
  716.                       long lineno_ptr,
  717.                       long reloc_number,
  718.                       long lineno_number,
  719.                       long alignment));
  720.  
  721. #ifndef tc_coff_symbol_emit_hook
  722. void tc_coff_symbol_emit_hook PARAMS ((struct symbol *));
  723. #endif
  724.  
  725. /* sanity check */
  726.  
  727. #ifdef TC_I960
  728. #ifndef C_LEAFSTAT
  729. hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it.
  730. #endif /* no C_LEAFSTAT */
  731. #endif /* TC_I960 */
  732. extern struct internal_scnhdr data_section_header;
  733. extern struct internal_scnhdr text_section_header;
  734.  
  735. /* Forward the segment of a forwarded symbol.  */
  736. #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src) \
  737.   (SF_GET_GET_SEGMENT (dest) \
  738.    ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
  739.    : 0)
  740.  
  741. #endif /* not BFD_ASSEMBLER */
  742.  
  743. /* Stabs in a coff file go into their own section.  */
  744. #define SEPARATE_STAB_SECTIONS
  745.  
  746. /* We need 12 bytes at the start of the section to hold some initial
  747.    information.  */
  748. extern void obj_coff_init_stab_section PARAMS ((segT));
  749. #define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg)
  750.  
  751. #endif /* OBJ_FORMAT_H */
  752.